var http = require( '../../utils/util' )
import { restUserCardcardTimeList,restUserCardRecharge,restUserCardRechargeLog } from '../../api/inquiry.js'
var app = getApp()


Page({
  data: {
      winWidth: 0,
      winHeight: 0,
      currentTab: 2,
	  infodata: [],
	  infodatacu: "",
  },
  onLoad: function() {

      var that = this;

      /**
       * 获取当前设备的宽高
       */
      wx.getSystemInfo( {
          success: function( res ) {
              that.setData( {
                  winWidth: res.windowWidth,
                  winHeight: res.windowHeight
              });
          }
      });
	  that.getData();
	  
	  
  },
    
//  tab切换逻辑
  swichNav: function( e ) {
      var that = this;
      if( this.data.currentTab === e.target.dataset.current ) {
          return false;
      } else {
          that.setData( {
              currentTab: e.target.dataset.current
          });
		  that.getData();
      }
  },

  bindChange: function( e ) {
      var that = this;
      that.setData( { currentTab: e.detail.current });
	  that.getData();
  },
  
  getData: function() {
	  var that = this;
	  var userId = app.globalData.wxlogin.userId;
	  //var userId = 44;
	  if(that.data.currentTab == 0){
		  // app.globalData.wxlogin.userId
		  restUserCardRecharge({'userId': userId}).then( res =>{
			   console.log(res)
			  if(res.code == 0){
				  that.setData( { infodata: res.data.list, infodatacu: res.data.userDataMap });
			  }
		  } );
	  }else if(that.data.currentTab == 1){
		  restUserCardRechargeLog({'userId': userId}).then( res =>{
			  console.log(res)
			  if(res.code == 0){
			  	that.setData( { infodata: res.data.list, infodatacu: res.data.userDataMap });
			  }
		  } );
	  }else {
		  restUserCardcardTimeList({'userId': userId}).then( res =>{
			   console.log(res)
			  if(res.code == 0){
			  	that.setData( { infodata: res.data.list, infodatacu: res.data.userDataMap });
			  }
		  } );
	  }
  }
  
  
})